import random
from PIL import Image, ImageDraw, ImageFont
import datetime


def makeDkb(event_0, event_1):
    im = Image.open('C:\\ProgramData\\LearningTools\\material\\img\\dkb.png')
    drawer = ImageDraw.Draw(im)
    # 获取字体对象
    imFont = ImageFont.truetype('C:\\ProgramData\\LearningTools\\material\\font\\AlibabaPuHuiTi-3-65-Medium.ttf', 550)
    # 绘制文字时设置字体
    day = datetime.datetime.now().strftime('%d')
    drawer.text((767, -27),text=day,font=imFont,fill=(0, 186, 173))

    imFont = ImageFont.truetype('C:\\ProgramData\\LearningTools\\material\\font\\AlibabaPuHuiTi-3-65-Medium.ttf', 108)
    day = datetime.datetime.now().strftime('%A')
    daylist = [
        ["Monday", "星期一"],
        ["Tuesday", "星期二"],
        ["Wednesday", "星期三"],
        ["Thursday", "星期四"],
        ["Friday", "星期五"],
        ["Saturday", "星期六"],
        ["Sunday", "星期日"],
        ]
    for i in range(7):
        if day == daylist[i][0]:
            drawer.text((1069, 663),text=daylist[i][1],font=imFont,fill=(166, 166, 166))
            break
    day = datetime.datetime.now().strftime('%B')
    daylist = [
        ["January", "一月大"],
        ["February", "二月平"],
        ["March", "三月大"],
        ["April", "四月小"],
        ["May", "五月大"],
        ["June", "六月小"],
        ["July", "七月大"],
        ["August", "八月大"],
        ["September", "九月小"],
        ["October", "十月大"],
        ["November", "十一月小"],
        ["December", "十二月大"]
        ]
    for i in range(12):
        if day == daylist[i][0]:
            if ((i == 10) | (i == 11)):
                drawer.text((962, 809),text=daylist[i][1],font=imFont,fill=(166, 166, 166))
            else:
                drawer.text((1069, 809),text=daylist[i][1],font=imFont,fill=(166, 166, 166))
            break
    imFont = ImageFont.truetype('C:\\ProgramData\\LearningTools\\material\\font\\AlibabaPuHuiTi-3-55-Regular.ttf', 70)
    day = (event_0[1] - datetime.date.today()).days
    drawer.text((100, 1125),text=str("距 " + event_0[0] + " 还剩 " + str(day) + "天"),font=imFont,fill=(255, 255, 255))
    day = (event_1[1] - datetime.date.today()).days
    drawer.text((100, 1254.2),text=str("距 " + event_1[0] + " 还剩 " + str(day) + "天"),font=imFont,fill=(255, 255, 255))
    return im


def makeDke():
    im = Image.open('C:\\ProgramData\\LearningTools\\material\\img\\dke.png')
    drawer = ImageDraw.Draw(im)
    # 获取字体对象
    imFont = ImageFont.truetype('C:\\ProgramData\\LearningTools\\material\\font\\AlibabaPuHuiTi-3-65-Medium.ttf', 400)
    # 绘制文字时设置字体
    fortune = [
        [range(1,6),"超级吉"],
        [range(6,21),"大吉"],
        [range(21,41),"中吉"],
        [range(41,61),"小吉"],
        [range(61,81),"中平"],
        [range(81,86),"小平"],
        [range(86,98),"小凶"],
        [range(98,100),"中凶"],
        [range(100,101),"大凶"]
    ]
    text = random.randint(1,100)
    for i in fortune:
        if text in i[0]:
            text=i[1]
            if text in ["超级吉", "大吉", "中吉", "小吉"]:
                drawer.text((100, 251),text=text,font=imFont,fill=(255, 87, 51))
            elif text in ["中平", "小平"]:
                drawer.text((100, 251),text=text,font=imFont,fill=(0, 186, 173))
            else:
                drawer.text((100, 251),text=text,font=imFont,fill=(255, 255, 255))
            break
    
    point_0 = random.randint(0,54)
    point_1 = random.randint(0,54)
    while point_0 == point_1:
        point_0 = random.randint(0,54)
        point_1 = random.randint(0,54)
    elements = [
        ["洗澡", "洗香香", "衣服怎么还没干？"],
        ["去食堂", "给自己加鸡腿", "饭都被抢完了"],
        ["学数学", "后面三道大题全对", "多选题全蒙错了"],
        ["写代码", "万行代码平地起", "bug根本修不完"],
        ["听歌", "耳机一戴，谁也不爱", "声音太大被邻居投诉"],
        ["出去玩", "羽毛球可好玩了", "一个能找到的人都没有"],
        ["和同学聊天", "双方聊的都很开心", "被老师发现"],
        ["买东西", "正好遇上打折", "余额不足"],
        ["干家务", "家里干干净净的", "被骂笨手笨脚"],
        ["打游戏", "被队友带飞了", "10把输9把"],
        ["纳财", "能要到好多Money", "一分钱都没拿上"],
        ["刷视频", "刷到有用的东西了", "又荒度一天"],
        ["学物理", "受力分析简简单单", "根本看不懂题目"],
        ["背单词", "离满分又近了一步", "前背后忘"],
        ["画画", "灵感如泉涌", "画一半画不下去了"],
        ["睡觉", "醒来精神状态极佳", "一夜醒来5次"],
        ["去图书馆", "找到心仪的书", "抢不上位置"],
        ["更新系统", "新版本有好东西诶", "怎么又崩了"],
        ["刷题", "噫！好！我会了！", "刷一半没动力了"],
        ["吃饭", "一顿能吃两碗饭", "吃多了会长胖"],
        ["开会", "准时结束会议", "超时两小时"],
        ["网购", "秒杀成功", "快递卡在半路了"],
        ["健身", "完成所有训练", "拉伤躺三天"],
        ["养植物", "开花了", "忘记浇水了"],
        ["订外卖", "准时送达", "汤洒了一袋子"],
        ["做实验", "数据完美符合预期", "仪器故障了"],
        ["晨跑", "呼吸新鲜空气", "踩到狗屎滑倒了"],
        ["做蛋糕", "好吃！", "烤箱温度调错了"],
        ["看星星", "许个愿", "天气预报没说多云啊？"],
        ["玩桌游", "连胜三局", "骰子掉进沙发缝"],
        ["写日记", "文思泉涌", "本子被同学偷看"],
        ["做手工", "被夸了", "满手胶水"],
        ["修电脑", "成功解决蓝屏问题", "装错驱动了"],
        ["穿新衣", "好看！", "溅上油渍洗也洗不掉"],
        ["玩魔术", "表演成功", "坏了，穿帮了"],
        ["养宠物", "可爱又乖巧", "专业拆家服务"],
        ["练书法", "写出满意作品", "墙上哪来的墨水？"],
        ["看日出", "好看", "睡过头错过了"],
        ["做报表", "数据精准零误差", "电脑死机"],
        ["拍合影", "构图太好看了", "有人闭眼了"],
        ["练瑜伽", "完成高难度体式", "抽筋下不来垫"],
        ["买球鞋", "抢到限量新款", "发现是假货"],
        ["玩摄影", "拍出获奖级作品", "坏了，储存卡忘带了"],
        ["练投篮", "连续命中二十个", "球卡在篮筐"],
        ["搞烘焙", "松软又好吃", "烤箱忘记预热了"],
        ["养金鱼", "你看这金鱼真好看", "喂太多撑死了"],
        ["玩拼图", "大工程！", "怎么少了一块"],
        ["演讲", "观众掌声雷动", "PPT排版怎么乱了"],
        ["玩风筝", "飞得超高超稳", "挂树上下不来"],
        ["玩轮滑", "完成花式动作", "刹不住撞墙"],
        ["养多肉", "长势喜人爆盆", "浇水过多烂根"],
        ["搞团建", "玩的开心", "游戏输被惩罚"],
        ["玩陶艺", "做出完美陶罐", "窑烧时开裂了"],
        ["练冥想", "进入深度禅定", "睡着打呼噜"],
        ["学化学", "简单！", "这个方程式怎么配？"]
    ]
    imFont = ImageFont.truetype('C:\\ProgramData\\LearningTools\\material\\font\\AlibabaPuHuiTi-3-65-Medium.ttf', 80)
    if text in ["超级吉", "大吉"]:
        drawer.text((100, 1101),text="宜：" + elements[point_0][0],font=imFont,fill=(255, 87, 51))
        drawer.text((100, 1394.2),text="诸事皆宜",font=imFont,fill=(255, 87, 51))
        imFont = ImageFont.truetype('C:\\ProgramData\\LearningTools\\material\\font\\AlibabaPuHuiTi-3-55-Regular.ttf', 70)
        drawer.text((100, 1212),text=elements[point_0][1],font=imFont,fill=(166, 166, 166))
        # drawer.text((100, 1505.2),text=elements[point_1][2],font=imFont,fill=(166, 166, 166))
    elif text == "大凶":
        drawer.text((100, 1101),text="诸事不宜",font=imFont,fill=(255, 255, 255))
        drawer.text((100, 1394.2),text="忌：" + elements[point_1][0],font=imFont,fill=(255, 255, 255))
        imFont = ImageFont.truetype('C:\\ProgramData\\LearningTools\\material\\font\\AlibabaPuHuiTi-3-55-Regular.ttf', 70)
        # drawer.text((100, 1212),text=elements[point_0][1],font=imFont,fill=(166, 166, 166))
        drawer.text((100, 1505.2),text=elements[point_1][2],font=imFont,fill=(166, 166, 166))
    else:
        drawer.text((100, 1101),text="宜：" + elements[point_0][0],font=imFont,fill=(255, 87, 51))
        drawer.text((100, 1394.2),text="忌：" + elements[point_1][0],font=imFont,fill=(255, 255, 255))
        imFont = ImageFont.truetype('C:\\ProgramData\\LearningTools\\material\\font\\AlibabaPuHuiTi-3-55-Regular.ttf', 70)
        drawer.text((100, 1212),text=elements[point_0][1],font=imFont,fill=(166, 166, 166))
        drawer.text((100, 1505.2),text=elements[point_1][2],font=imFont,fill=(166, 166, 166))
    return im
